﻿using System;
using System.Text;
using System.Data;
using System.Collections.Generic;
using MySql.Data.MySqlClient;
using Think.Lenovo.Com.Models;

namespace Think.Lenovo.Com.DataAccess
{
    public class News_userInfo
    {
        public long Add(News_user nuser)
        {
            String conn = System.Configuration.ConfigurationManager.ConnectionStrings["MySqlHost"].ConnectionString;

            //sql语句
            StringBuilder sql = new StringBuilder(128);
            sql.Append("insert into ")
                .Append("tbl_news_user_know (userid, newsid,integral)")
                .Append("values(@userid,@newsid,@integral)");


            MySqlParameter[] ps = new MySqlParameter[] {
                    new MySqlParameter("@userid",MySqlDbType.Int32),
                    new MySqlParameter("@newsid",MySqlDbType.Int32),
                    new MySqlParameter("@integral",MySqlDbType.Int32)
                };

            ps[0].Value = nuser.Userid;
            ps[1].Value = nuser.Newsid;
            ps[2].Value = nuser.Integral;

            long id = MysqlHelper.Insert(conn, sql.ToString(), ps);
            return id;
        }

        public int GetCount(int newsid,int userid)
        {
            String conn = System.Configuration.ConfigurationManager.ConnectionStrings["MySqlHost"].ConnectionString;
            StringBuilder sql = new StringBuilder(128);

            sql.Append("Select Count(Id) From tbl_news_user_know where newsid="+newsid+" and userid="+userid);
        
            Object obj = MysqlHelper.ExecuteScalar(conn, sql.ToString());
            return obj == null ? 0 : Convert.ToInt32(obj);
        }

    }
}
